<?php 
require_once "init-ise.php";
session_start();
$result = "No result";
$action = "undefined";
$login = new LoginManager();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$action = $_POST['action'];
	if ($action === 'logout') {
		$result = $login->logout() ? "Logged out" : "Log out failed";
	} else if ($action === 'login') {
		$username = $_POST['username'];
		$password = $_POST['password'];
		$result = $login->login($username, $password) ? "Logged in" : "Login failed";
		$result .= " as ".$username." with password ".$password;
	}
}
?>
<html>
<head>
	<title>login test</title>
</head>
<body>
	<h1>Login test</h1>
	<h2>Call:</h2>
	<p>
	<?php
	print "Action was ".$action." with result ".$result;  
	?>
	</p>
	<h2>Currently logged in as:</h2>
	<p>
	<?php 
	if ($login->isLoggedIn()) {
		$user = $login->getWebuser();
		print "Logged in as ".$user->getCustomer();
	} else {
		print "Currently not logged in.";
	}
	?>
	</p>
	<form method="post" action="">
		<fieldset>
		<input type="hidden" name="action" value="login" />
		<input type="text" name="username" value="" />
		<input type="password" name="password" value="" />
		<input type="submit" value="Login" />
		</fieldset>
	</form>
	<form method="post" action="">
		<fieldset>
		<input type="hidden" name="action" value="logout" />
		<input type="submit" value="Logout" />
		</fieldset>
	</form>
</body>
</html>